package com.xc.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xc.content.mapper.TeachplanMediaMapper;
import com.xc.content.model.dto.TeachplanMediaDto;
import com.xc.content.model.po.TeachplanMedia;
import com.xc.content.service.TeachplanMediaService;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author daxiaa
 */
@Slf4j
@Service
public class TeachplanMediaServiceImpl extends ServiceImpl<TeachplanMediaMapper, TeachplanMedia> implements TeachplanMediaService {

    /**
     * 课程计划绑定绑定媒体---视频，文档等
     */
    @Override
    public void bindTeachplanMedia(TeachplanMediaDto dto) {
        TeachplanMedia teachplanMedia = new TeachplanMedia();
        teachplanMedia.setMediaId(dto.getMediaId());
        teachplanMedia.setTeachplanId(dto.getTeachplanId());
//        teachplanMedia.setCourseId(dto.getCourseId());
        teachplanMedia.setMediaFilename(dto.getFileName());
        saveOrUpdate(teachplanMedia);

    }

    /**
     * 删除关联的媒体
     *
     * @param teachplanId
     * @param mediaId
     */
    @Override
    public void deleteTeachplanMedia(Long teachplanId, String mediaId) {
        LambdaQueryWrapper<TeachplanMedia> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(teachplanId != null, TeachplanMedia::getTeachplanId, teachplanId)
                .eq(StringUtils.isNotEmpty(mediaId), TeachplanMedia::getMediaId, mediaId);
        remove(lambdaQueryWrapper);
    }
}
